import { getUserInfo, saveUserInfo } from '@/utils/stroage'

export default {
    namespaced: true,
    state: {
        // userinfo: getUserInfo() // 先从localstorage中取。
        userinfo: '', // 先从localstorage中取。480ada0593b245438cd92056a05ee387 ea50587a6d744820885753673bb2ef07 
        userCode: ''
    },
    getters: {
        // 直接获取是否登录（以token是否为空来判断）
        isLogin: state => {
            return state.userinfo.token !== ''
        },
        userinfo: state => {
            return state.userinfo
        },
        userCode: state => {
            return state.userCode
        },
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.userinfo = payload
                // saveUserInfo(payload)
        },
        updateUserCode(state, newCode) {
            state.userCode = newCode
        },
    },
    actions: {
        updateValue({ commit }, payload) {
            commit('updateValue', payload)
        }
    }
}